<!--
  我的档案主页
-->
<template>
  <div v-if=$store.state.login_status>
    <el-link v-if=this.$store.state.myRecord_status&&this.$store.state.record_status @click="getRecord" type="primary">点我刷新档案信息</el-link>
    <el-table v-if=this.$store.state.myRecord_status&&this.$store.state.record_status v-loading="loading" :data="records" border stripe style="width: 100%">
      <el-table-column prop="id" label="档案编号"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="gender" label="性别"></el-table-column>
      <el-table-column prop="nation" label="民族"></el-table-column>
      <el-table-column prop="idnumber" label="身份证号"></el-table-column>
      <el-table-column prop="createDate" label="建档时间"></el-table-column>
      <el-table-column prop="statusString" label="状态"></el-table-column>
      <el-table-column label="操作">
        <el-link @click="openRecord" :underline=false type="primary">查看档案</el-link>
        <el-link href="#/index/worker/record/recordApply" :underline=false type="success">申请修改</el-link>
      </el-table-column>
    </el-table>
    <router-view></router-view>
  </div>
</template>

<script>

import instance from "../../../utils/request";

export default {
  name: "Index",
  data(){
    return {
      msg:'我的档案',
      record:'',    //档案名称
      records:[     //档案对象
      ],
      loading: true,    //加载标志
    }
  },
  methods:{
    //打开档案方法
    openRecord(){
      this.$router.push('/index/worker/record/myRecord');
      this.$store.commit('changeMyRecord_StatusToFalse');
    },
    //刷新页面方法
    getRecord(){
      this.records=[];
      let _this = this;
      instance.post('/api/record/workerPortal').then(function (res) {
        if(res.data.code === 200){
          //查询成功后的操作
          _this.record = res.data.data;
          _this.records.push(_this.record);
          _this.loading = false;
          _this.$store.state.record = res.data.data;
        }
      }).catch(function (err) {
        console.log(err);
      });
    }
  },
  //页面加载时获取档案信息
  created() {
    let _this = this;
    instance.post('/api/record/workerPortal').then(function (res) {
      _this.loading = false;
      if(res.data.code === 208){
        _this.$alert('档案信息不存在，请先创建档案','错误提示',{
          confirmButtonText:'确定',
          callback:action => {
            //关闭对话框后跳转创建档案页面
            _this.$store.commit('changeMyRecord_StatusToTrue');
            _this.$router.push('/index/worker/record/createRecord');
          }
        });
      }
      if(res.data.code === 200){
        _this.records.push(res.data.data);
        _this.$store.state.record = res.data.data;
      }
    }).catch(function (err) {
      console.log(err);
    });
  }
}
</script>

<style scoped>

</style>
